<div class="modal-header">
    <div class="close">×</div>
    <div class="modal-title" id="modal-title">
        <span class="active">发布详情</span>
    </div>
</div>
<div class="publish-details">
    <div class="alarm-header">
        <div style="width:12%">序号</div>
        <div style="width:18%">发布手段</div>
        <div style="width:18%">发布时间</div>
        <div style="width:34%">详情</div>
        <div style="width:18%">状态</div>
    </div>
    <div class="details-body">
    </div>
</div>
<script>
    $("#modal_publish_details .close").click(function () {
        $("#modal_publish_details,.modal-backdrop").remove();
    });
    initBody();
    function initBody() {
        var data = $("#modal_publish_details").data('dataObj');
        if (!data) return;
		var productTypeName = $("#productType option:selected").text();
        var content = [], $content;
		if (productTypeName == '预警信号') {
			loading.add('#modal_monitor');
			$.ajax({
				url: api.external.getAlertMessage,
				type: "POST",
				contentType: "application/json;charset=utf-8",
				dataType: 'json',
				data: JSON.stringify({identifier: data.Identifier}),
				success: function (res) {
					loading.remove();
					if (!res.FBInfo || res.FBInfo.length <= 0) return;
					res.FBInfo = res.FBInfo.sort(function (i, j) {
						return j.FeedbackStatus - i.FeedbackStatus
					});
					res.FBInfo.forEach(function (item, index) {
						var time = item.ReceiveTime;
						var isPubfail = item.FeedbackStatus == '0' ? '' : 'pubfail';
						content.push(`<div class="details-item">
									<div style="width: 12%">${++index}</div>
									<div style="width: 18%">${data.styleName}</div>
									<div style="width: 18%">${new Date(time).format('hh:mm')}</div>
									<div title="${item.ClientID == undefined ? '' : item.ClientID}" style="width: 34%">${item.ClientID == undefined ? '' : item.ClientID}</div>
									<div class="${isPubfail}" style="width: 18%">${item.FeedbackStatus == '0' ? '发布成功' : '发布失败'}</div>
									</div>`);
					})
					$(".details-body").empty().append(content);
				},
				error: function(){
					loading.remove();
				}
			})
		} else{
			var failData = data.details.filter(function(i,j){
				return Number(i.STATUS) !== 0 && Number(i.STATUS) !== 1;
			})
			var succesData = data.details.filter(function(i,j){
				return Number(i.STATUS) === 0 || Number(i.STATUS) === 1;
			})
			succesData.sort(function(i,j){
				return Number(i.STATUS) - Number(j.STATUS);
			})
			data.details = failData.concat(succesData);
            data.details.forEach(function (item, index) {
                var time = item.publistDate;
				var isPubfail = Number(item.STATUS) === 0 ? '' : Number(item.STATUS) === 1 ? '' : 'pubfail';
                if (!time) {
                    time = data.publistDate;
                }
                content.push(`<div class="details-item">
                            <div style="width: 12%">${++index}</div>
                            <div style="width: 18%">${item.STYLE}</div>
                            <div style="width: 18%">${new Date(time).format('hh:mm')}</div>
                            <div title="${item.clientId == undefined ? '' : item.clientId}" style="width: 34%">${item.clientId == undefined ? '' : item.clientId}</div>
                            <div class="${isPubfail}" style="width: 18%">${Number(item.STATUS) === 0 ? '在发' : Number(item.STATUS) === 1 ? '发布成功' : '发布失败'}</div>
                            </div>`);
            })
			$(".details-body").empty().append(content);
		}
    }
</script>